<form action="{:U('Permission/user_authorize')}" method="post">
<table class="table">
	<thead>
		<tr>
			<th>&nbsp;</th>
			<th>{:L('MODULE')}</th>
			<th>{:L('VISIBLE')}</th>
			<th>{:L('BROWSE')}</th>
			<th>{:L('CREATE')}</th>
			<th>{:L('EDIT')}</th>
			<th>{:L('DELETE')}</th>
			<th>{:L('EXPORT')}</th>
		</tr>
	</thead> 
	<input type="hidden" name="position_id" value="{$position_id}"/>
	<tbody>
		<tr>
			<td><input type="checkbox" rel="12" class="check_all" name="check_leads"/></td>
			<td>{:L('USER')}</td>
			<td><input <php>if(in_array('user/index', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list12" type="checkbox" name="per[]" value="user/index"></td>
			<td><input <php>if(in_array('user/view', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list12" type="checkbox" name="per[]" value="user/view"></td>
			<td><input <php>if(in_array('user/add', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list12" type="checkbox" name="per[]" value="user/add"></td>
			<td><input <php>if(in_array('user/edit', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list12" type="checkbox" name="per[]" value="user/edit"></td>
			<td><input <php>if(in_array('user/delete', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list12" type="checkbox" name="per[]" value="user/delete"></td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td><input type="checkbox" rel="4" class="check_all" name="check_leads"/></td>
			<td>{:L('LEADS')}</td>
			<td><input <php>if(in_array('leads/index', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list4" type="checkbox" name="per[]" value="leads/index"></td>
			<td><input <php>if(in_array('leads/view', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list4" type="checkbox" name="per[]" value="leads/view"></td>
			<td><input <php>if(in_array('leads/add', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list4" type="checkbox" name="per[]" value="leads/add"></td>
			<td><input <php>if(in_array('leads/edit', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list4" type="checkbox" name="per[]" value="leads/edit"></td>
			<td><input <php>if(in_array('leads/delete', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list4" type="checkbox" name="per[]" value="leads/delete"></td>
			<td><input <php>if(in_array('leads/export', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list4" type="checkbox" name="per[]" value="leads/export"></td>
		</tr>
		<tr>
			<td width="3%"><input type="checkbox" rel="1" class="check_all" name="check_business"/></td>
			<td>{:L('BUSINESS')}</td>
			<td><input <php>if(in_array('business/index', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list1" type="checkbox" name="per[]" value="business/index"></td>
			<td><input <php>if(in_array('business/view', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list1" type="checkbox" name="per[]" value="business/view"></td>
			<td><input <php>if(in_array('business/add', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list1" type="checkbox" name="per[]" value="business/add"></td>
			<td><input <php>if(in_array('business/edit', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list1" type="checkbox" name="per[]" value="business/edit"></td>
			<td><input <php>if(in_array('business/delete', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list1" type="checkbox" name="per[]" value="business/delete"></td>
			<td><input <php>if(in_array('business/export', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list1" type="checkbox" name="per[]" value="business/export"></td>
		</tr>
		<tr>
			<td><input type="checkbox" rel="3" class="check_all" name="check_customer"/></td>
			<td>{:L('CUSTOMER')}</td>
			<td><input <php>if(in_array('customer/index', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list3" type="checkbox" name="per[]" value="customer/index"></td>
			<td><input <php>if(in_array('customer/view', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list3" type="checkbox" name="per[]" value="customer/view"></td>
			<td><input <php>if(in_array('customer/add', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list3" type="checkbox" name="per[]" value="customer/add"></td>
			<td><input <php>if(in_array('customer/edit', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list3" type="checkbox" name="per[]" value="customer/edit"></td>
			<td><input <php>if(in_array('customer/delete', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list3" type="checkbox" name="per[]" value="customer/delete"></td>
			<td><input <php>if(in_array('customer/export', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list3" type="checkbox" name="per[]" value="customer/export"></td>
		</tr>
		<tr>
			<td><input type="checkbox" rel="9" class="check_all" name="check_contract"/></td>
			<td>{:L('CONTRACT')}</td>
			<td><input <php>if(in_array('contract/index', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list9" type="checkbox" name="per[]" value="contract/index"></td>
			<td><input <php>if(in_array('contract/view', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list9" type="checkbox" name="per[]" value="contract/view"></td>
			<td><input <php>if(in_array('contract/add', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list9" type="checkbox" name="per[]" value="contract/add"></td>
			<td><input <php>if(in_array('contract/edit', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list9" type="checkbox" name="per[]" value="contract/edit"></td>
			<td><input <php>if(in_array('contract/delete', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list9" type="checkbox" name="per[]" value="contract/delete"/></td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td><input type="checkbox" rel="10" class="check_all" name="check_finance"/></td>
			<td>{:L('FINANCE')}</td>
			<td><input <php>if(in_array('finance/index', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list10" type="checkbox" name="per[]" value="finance/index"></td>
			<td><input <php>if(in_array('finance/view', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list10" type="checkbox" name="per[]" value="finance/view"></td>
			<td><input <php>if(in_array('finance/add', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list10" type="checkbox" name="per[]" value="finance/add"></td>
			<td><input <php>if(in_array('finance/edit', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list10" type="checkbox" name="per[]" value="finance/edit"></td>
			<td><input <php>if(in_array('finance/delete', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list10" type="checkbox" name="per[]" value="finance/delete"></td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td><input type="checkbox" rel="2" class="check_all" name="check_product"/></td>
			<td>{:L('PRODUCT')}</td>
			<td><input  <php>if(in_array('product/index', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list2" type="checkbox" name="per[]" value="product/index"></td>
			<td><input <php>if(in_array('product/view', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list2" type="checkbox" name="per[]" value="product/view"></td>
			<td><input <php>if(in_array('product/add', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list2" type="checkbox" name="per[]" value="product/add"></td>
			<td><input <php>if(in_array('product/edit', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list2" type="checkbox" name="per[]" value="product/edit"></td>
			<td><input <php>if(in_array('product/delete', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list2" type="checkbox" name="per[]" value="product/delete"></td>
			<td><input <php>if(in_array('product/export', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list2" type="checkbox" name="per[]" value="product/export"></td>
		</tr>
		<tr>
			<td><input  type="checkbox" rel="5" class="check_all" name="check_contacts"/></td>
			<td>{:L('CONTACTS')}</td>
			<td><input <php>if(in_array('contacts/index', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list5" type="checkbox" name="per[]" value="contacts/index"></td>
			<td><input <php>if(in_array('contacts/view', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list5" type="checkbox" name="per[]" value="contacts/view"></td>
			<td><input <php>if(in_array('contacts/add', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list5" type="checkbox" name="per[]" value="contacts/add"></td>
			<td><input <php>if(in_array('contacts/edit', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list5" type="checkbox" name="per[]" value="contacts/edit"></td>
			<td><input <php>if(in_array('contacts/delete', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list5" type="checkbox" name="per[]" value="contacts/delete"></td>
			<td><input <php>if(in_array('contacts/export', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list5" type="checkbox" name="per[]" value="contacts/export"></td>
		</tr>
		<tr>
			<td><input type="checkbox" rel="6" class="check_all" name="check_task"/></td>
			<td>{:L('TASK')}</td>
			<td><input <php>if(in_array('task/index', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list6" type="checkbox" name="per[]" value="task/index"></td>
			<td><input <php>if(in_array('task/view', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list6" type="checkbox" name="per[]" value="task/view"></td>
			<td><input <php>if(in_array('task/add', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list6" type="checkbox" name="per[]" value="task/add"></td>
			<td><input <php>if(in_array('task/edit', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list6" type="checkbox" name="per[]" value="task/edit"></td>
			<td><input  <php>if(in_array('task/delete', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list6" type="checkbox" name="per[]" value="task/delete"></td>
			<td><input <php>if(in_array('task/export', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list6" type="checkbox" name="per[]" value="task/export"></td>
		</tr>
		<tr>
			<td><input type="checkbox" rel="7" class="check_all" name="check_event"/></td>
			<td>{:L('EVENT')}</td>
			<td><input <php>if(in_array('event/index', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list7" type="checkbox" name="per[]" value="event/index"></td>
			<td><input <php>if(in_array('event/view', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list7" type="checkbox" name="per[]" value="event/view"></td>
			<td><input <php>if(in_array('event/add', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list7" type="checkbox" name="per[]" value="event/add"></td>
			<td><input <php>if(in_array('event/edit', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list7" type="checkbox" name="per[]" value="event/edit"></td>
			<td><input <php>if(in_array('event/delete', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list7" type="checkbox" name="per[]" value="event/delete"></td>
			<td><input <php>if(in_array('event/export', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list7" type="checkbox" name="per[]" value="event/export"></td>
		</tr>
		<tr>
			<td><input type="checkbox" rel="13" class="check_all" name="check_marketing"/></td>
			<td>{:L('MARKETING')}</td>
			<td colspan="5">{:L('ALL SEND EMAIL AND SMS AND SMSRECORD')} <input <php>if(in_array('setting/marketing', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list13" type="checkbox" name="per[]" value="setting/marketing"></td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td><input type="checkbox" rel="8" class="check_all" name="check_knowledge"/></td>
			<td>{:L('KNOWLEDGE')}</td>
			<td><input <php>if(in_array('knowledge/index', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list8" type="checkbox" name="per[]" value="knowledge/index"></td>
			<td><input <php>if(in_array('knowledge/view', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list8" type="checkbox" name="per[]" value="knowledge/view"></td>
			<td><input <php>if(in_array('knowledge/add', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list8" type="checkbox" name="per[]" value="knowledge/add"></td>
			<td><input <php>if(in_array('knowledge/edit', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list8" type="checkbox" name="per[]" value="knowledge/edit"></td>
			<td><input <php>if(in_array('knowledge/delete', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list8" type="checkbox" name="per[]" value="knowledge/delete"></td>
			<td><input <php>if(in_array('knowledge/export', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list8" type="checkbox" name="per[]" value="knowledge/export"></td>
		</tr>
		<tr>
			<td><input type="checkbox" rel="11" class="check_all" name="check_announce"/></td>
			<td>{:L('announcement manager')}</td>
			<td><input <php>if(in_array('announcement/index', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list11" type="checkbox" name="per[]" value="announcement/index"></td>
			<td><input <php>if(in_array('announcement/view', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list11" type="checkbox" name="per[]" value="announcement/view"></td>
			<td><input <php>if(in_array('announcement/add', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list11" type="checkbox" name="per[]" value="announcement/add"></td>
			<td><input <php>if(in_array('announcement/edit', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list11" type="checkbox" name="per[]" value="announcement/edit"></td>
			<td><input <php>if(in_array('announcement/delete', $owned_permission)){ echo 'checked="checked"';}</php> class="check_list11" type="checkbox" name="per[]" value="announcement/delete"></td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td colspan="3">&nbsp;</td>
			<td colspan="5">
				<input class="btn btn-primary" id="sub_btn" name="submit" type="button" value="{:L(SAVE)}"> &nbsp; <input class="btn" type="button" onclick="$('#dialog-authorize').dialog('close');" value="{:L('CANCEL')}"/>
			</td>
		</tr>
	</tbody>
</table>
</form>
<script type="text/javascript">
	$(function(){
		$(".check_all").click(function(){
			var rel = $(this).attr('rel');
			$("input[class='check_list"+rel+"']").prop('checked', $(this).prop("checked"));
		});
	});
	$("#sub_btn").click(
		function() {
			var perlist = [];
			$('input:checkbox:checked').each(function(key,val){
				perlist.push($(val).val()) 
			});
			if(perlist && perlist.length > 0){
				var perlist_str = perlist.join(',') ;
			}else{
				var perlist_str = '' ;
			}
			var position_id = {$position_id};
			$.get('{:U("permission/user_authorize")}',{perlist:perlist_str, auth:1,position_id:position_id}, function(data){
				alert(data.data);
				$('#dialog-authorize').dialog('close');
			}, 'json');
		}	
	);
</script>